package com.kevin.Code.Greedy;

import java.util.Arrays;

/**
 * @author Vinlee Xiao
 * @Classname AssignCookies
 * @Description Leetcode 455 分发饼干  简单 贪心算法
 * @Date 2021/9/30 11:11
 * @Version 1.0
 */
public class AssignCookies {

    /**
     * @param g
     * @param s
     * @return
     */
    public int findContentChildren(int[] g, int[] s) {

        int gLen = g.length;
        int sLen = s.length;

        if (sLen == 0) {
            return 0;
        }
        //按从小到大排序
        Arrays.sort(g);
        //按从大到小排序
        Arrays.sort(s);

        int left = 0;
        int right = 0;

        //用于记录满足要求的饼干数量
        int count = 0;

        while (left < gLen && right < sLen) {

            if (g[left] <= s[right]) {
                count++;
                left++;
            }

            right++;
        }


        return count;
    }
}
